

$special_pkgs_dic = @{
    "ubuntu" = @{
        "14.04" = "";
        "15.04" = "";
        "16.04" = "";
        "17.04" = "";
        "18.04" = "fish nnn";
        "19.04" = "fish nnn";
        "20.04" = "fish nnn";
        "21.04" = "fish nnn";
        "22.04" = "fish nnn";
        "23.04" = "fish nnn";
        "14.10" = "";
        "15.10" = "";
        "16.10" = "";
        "17.10" = "";
        "18.10" = "fish nnn";
        "19.10" = "fish nnn";
        "20.10" = "fish nnn";
        "21.10" = "fish nnn";
        "22.10" = "fish nnn";
    };
    "debian" = @{
        "8" = "";
        "9" = "";
        "10" = "fish nnn";
        "11" = "fish nnn";
    };
    "fedora" = @{
        "25" = "";
        "26" = "";
        "27" = "";
        "28" = "";
        "29" = "";
        "30" = "";
        "31" = "";
        "32" = "";
        "33" = "";
        "34" = "";
        "35" = "";
        "36" = "";
        "37" = "";
    };
    "rhel" = @{
        "6" = "";
        "7" = "";
        "8" = "";
        "9" = "";
    };
    "centos" = @{
        "6" = "";
        "7" = "";
        "8" = "";
    };
    "centos-stream" = @{
        "8" = "";
        "9" = "";
    };
    "alma" = @{
        "8" = "";
        "9" = "";
    };
    "rocky" = @{
        "8" = "";
        "9" = "";
    };
    "ol" = @{
        "6" = "";
        "7" = "";
        "8" = "";
        "9" = "";
    };
    "alpine" = @{
        "36" = "";
        "37" = "";
        "38" = "";
        "39" = "";
        "310" = "";
        "311" = "";
        "312" = "";
        "313" = "";
        "314" = "";
        "315" = "";
        "316" = "";
        "317" = "";
    };
    "arch" = "";
    "manjaro" = "";
    "nixos" = "";
    "freebsd" = @{
        "11" = "";
        "12" = "";
        "13" = "";
    }

}

$pkg_mgt = @{
    "debian" = "";
    "ubuntu" = "";
    "kali" = "";
    "alpine" = "";
}

# echo $special_pkgs_dic
# echo $special_pkgs_dic.ubuntu
# echo $special_pkgs_dic["ubuntu"]["22.04"]

# $hash = @{"Fruit" = "Apple"; Color="Red"; Count=5}

# echo $hash.Fruit
# echo "lgf"



[System.Reflection.Assembly]::Load("System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") | Out-Null


$Form = New-Object System.Windows.Forms.Form
$progressBar1 = New-Object System.Windows.Forms.ProgressBar;
$button1 = New-Object System.Windows.Forms.Button;
$label1 = New-Object System.Windows.Forms.Label;

#
#  progressBar1
#

$progressBar1.Location = New-Object System.Drawing.Point(179, 409);
$progressBar1.Name = "progressBar1";
$progressBar1.Size = New-Object System.Drawing.Size(609, 29);
$progressBar1.TabIndex = 1;
#
#   label1
#
$label1.AutoSize = $true;
$label1.Location = New-Object System.Drawing.Point(12, 418);
$label1.Name = "label1";
$label1.Size = New-Object System.Drawing.Size(50, 20);
$label1.TabIndex = 2;
$label1.Text = "我是状态";


$OpenTheDoor = {
    param($Enable)
    #给后台job传递一个callback方法,在工作结束之后修改button状态
    $Form.Invoke(
        {
            $button1.Enabled = $Enable
        }
    )
}

$ReportProgress = {
    param($Progress, $Activity, $Status)
    $Form.Invoke({
            $label1.Text = "$Activity $Status"
            $progressBar1.Value = $Progress
        })

}

$button1.Location = New-Object System.Drawing.Point(257, 150);
$button1.Name = "button1";
$button1.Size = New-Object System.Drawing.Size(284, 103);
$button1.TabIndex = 0;
$button1.Text = "工作使我快乐";
$button1.UseVisualStyleBackColor = $true;
$button1.Add_Click({
        # 干活之前开启免打扰模式
        $button1.Enabled = $false;
        Start-ThreadJob -ScriptBlock {
            param($Callback,$ProgressReporter)
            Write-Host "我开工作了。。。"
            $count = 1;
            $totalJob = 100
            do {
                Write-Host "完成第 $count 份工作"
                # 通知老板我的工作进度
                Invoke-Command -ScriptBlock $ProgressReporter -ArgumentList $count,"努力工作",$count
                Start-Sleep  -Milliseconds 100
                $count++
            } while ($count -le $totalJob)
            Write-Host "工作做完，开始浪了。。。"

            # 通知老板我的工作已经完成100%
            Invoke-Command -ScriptBlock $ProgressReporter -ArgumentList 100,"工作完成^_^",100

            # 干完活之后通知主线程继续接活。
            Invoke-Command -ScriptBlock $Callback -ArgumentList $true

        } -StreamingHost $Host -ArgumentList $OpenTheDoor, $ReportProgress
    })

$Form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Font;
$Form.ClientSize = New-Object System.Drawing.Size(800, 450);
$Form.Name = "Form1";
$Form.Text = "PowerShell Form (Hello world!)";
$Form.Controls.Add($label1);
$Form.Controls.Add($progressBar1);
$Form.Controls.Add($button1);
# $Form.ResumeLayout($false);
# $Form.ShowDialog()

[System.Windows.Forms.Application]::SetHighDpiMode('SystemAware')  | Out-Null;
[System.Windows.Forms.Application]::EnableVisualStyles() | Out-Null;
[System.Windows.Forms.Application]::Run($Form) | Out-Null;
